//
//  HMEmoticonButton.swift
//  WeiBo
//
//  Created by Feng on 2017/6/16.
//  Copyright © 2017年 feng. All rights reserved.
//

import UIKit

class HMEmoticonButton: UIButton {

    var emoticon: HMEmoticon?
    {
        didSet {
            
            guard let currentEmoticon = emoticon else {
                return
            }
            
            //设置button为不隐藏
            self.isHidden = false
            
            if currentEmoticon.type == "0"
            {
                //  named: 指定的图片名表示在mainbundle里面加载这个图片，而我们的表情图片在emoticonbundle
                //  traitCollection: 图片的特性信息
                let image = UIImage(named: currentEmoticon.path!, in: HMEmoticonTools.sharedTools.emoticonBundle, compatibleWith: nil)
                
                self.setImage(image, for: .normal)
                self.setTitle(nil, for: .normal)
            }
            else
            {
                let title = (currentEmoticon.code! as NSString).emoji()
                
                self.setImage(nil, for: .normal)
                self.setTitle(title, for: .normal)
            }
        }
    }
}
